﻿// CListDlg.cpp: 实现文件
//

#include "pch.h"
#include "SalaryManagement.h"
#include "CListDlg.h"
#include"InfoFile.h"


// CListDlg

IMPLEMENT_DYNCREATE(CListDlg, CFormView)

CListDlg::CListDlg()
	: CFormView(IDD_LIST)
{

}

CListDlg::~CListDlg()
{
}

void CListDlg::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LIST1, m_list);
}

BEGIN_MESSAGE_MAP(CListDlg, CFormView)
END_MESSAGE_MAP()


// CListDlg 诊断

#ifdef _DEBUG
void CListDlg::AssertValid() const
{
	CFormView::AssertValid();
}

#ifndef _WIN32_WCE
void CListDlg::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif
#endif //_DEBUG


// CListDlg 消息处理程序


void CListDlg::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();

	// TODO: 在此添加专用代码和/或调用基类


	//列表控件     获取库存信息
	m_list.SetExtendedStyle(m_list.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
	CString filed[] = { L"商品ID",L"商品名称", L"商品价格",L"商品库存数量" };
	for (int i = 0; i < sizeof(filed)/sizeof(filed[0]); i++) {
		m_list.InsertColumn(i, filed[i], LVCFMT_CENTER, 90);
	}
	CInfoFile file;
	CString str;
	int i = 0;
	file.ReadDocline();
	for (auto it : file.ls) {
		str.Format(L"%d", it.id);
		m_list.InsertItem(i, str);
		str.Empty();
		int column = 1;
		m_list.SetItemText(i, column++, CString(it.name.c_str()));
		str.Format(L"%d", it.price);
		m_list.SetItemText(i, column++, str);
		str.Empty();
		str.Format(L"%d", it.num);
		m_list.SetItemText(i, column++, str);
		str.Empty();
		++i;
	}




}
